<%@page isELIgnored="false"%>
<%@page import="org.jivesoftware.openfire.plugin.model.ChatLogs"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="org.jivesoftware.util.ParamUtils"%>
<%@page import="org.jivesoftware.openfire.plugin.chatlogs.DbChatLogsManager"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>聊天记录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="pageID" content="chatLogs-service"/>
</head>

<%
    //YouXinChatLogsPlugin plugin = (YouXinChatLogsPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("chatlogs");
    String sender = ParamUtils.getParameter(request, "sender");
    String receiver = ParamUtils.getParameter(request, "receiver");
    String content = ParamUtils.getParameter(request, "content");
    ChatLogs entity = new ChatLogs();
    entity.setContent(content);
    entity.setReceiver(receiver);
    entity.setSender(sender);
    DbChatLogsManager logsManager = DbChatLogsManager.getInstance();
    List<ChatLogs> logs = logsManager.query(entity);
%>

<body>
<!--
<div class="jive-contentBoxHeader">所有联系人</div>
<div class="jive-contentBox">
    <a href="${pageContext.request.contextPath }/plugins/chatlogs/ChatLogsServlet?action=all!contact">查看</a>
</div>
-->

<div class="jive-contentBoxHeader">查询</div>
<div class="jive-contentBox">
    <form action="chatLogs-service.jsp">
        发送人：<input type="text" name="sender" value="${param.sender }">
        接收人：<input type="text" name="receiver" value="${param.receiver }">
        内容：<input type="text" name="content" value="${param.content }">
        <%--发送时间：<input type="text" name="createDate" value="${param.createDate }" placeholder="yyyy-MM-dd" >--%>
        <input type="submit" value="查询">
        <input type="reset">
    </form>
</div>

<div class="jive-table">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <thead>
        <tr>
            <th>发送人</th>
            <th>接收者</th>
            <th>内容</th>
            <th>发送时间</th>
            <th>删除</th>
        </tr>
        </thead>
        <tbody>
        <% for (int i = 0, len = logs.size(); i < len; i++) {
            ChatLogs log = logs.get(i);
        %>
        <tr class="jive-<%= i % 2 == 0 ? "even" : "odd" %>">
            <c:set var="content" value="<%=log.getContent()%>"></c:set>
            <td><%=log.getSender() %></td>
            <td><%=log.getReceiver() %></td>
            <td style="width: 40%;">${fn:escapeXml(content)}</td>
            <td><%=log.getCreateDate() %></td>
            <td><a href="${pageContext.request.contextPath }/plugins/chatlogs/ChatLogsServlet?action=remove!contact&messageId=<%=log.getMessageId() %>">点击删除</a></td>
        </tr>
        <% } %>
        </tbody>
    </table>
</div>
</body>
</html>